import java.security.PublicKey;
//双向链表(尾插，头删）实现队列
public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

    }
    public ListNode head;
    public ListNode last;

    //入队
    public void offer(int val) {
        ListNode node = new ListNode(val);
        //尾插
        if(head == null) {
            head = last = node;
        } else {
            last.next = node;
            node.prev = last;
            last = node;
        }
    }

    //出队
    public int poll() {
        //空队列
        if(head == null) {
            return -1;
        }
        //一个节点
        int val = -1;
        if (head.next == null) {
            val = head.val;
            head = null;
            last = null;
            return val;
        }
        val = head.val;
        head = head.next;
        head.prev = null;
        return val;
    }

    //判断是否为空
    public boolean empty() {
        return head == null;
    }

    public int peek() {
        if (head == null) {
            return -1;
        }
        return head.val;
    }
}
